package com.jdjw.modules.buscommentjcllzzfw.service.impl;

import com.jdjw.common.ResponseResult;
import com.jdjw.modules.buscommentjcllzzfw.entity.BusCommentJcllzzfw;
import com.jdjw.modules.buscommentjcllzzfw.mapper.BusCommentJcllzzfwMapper;
import com.jdjw.modules.buscommentjcllzzfw.service.BusCommentJcllzzfwService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdjw.utils.HttpRequestUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 检察联络站评论数据-对接建达-存放建达检察联络站需要转至政法委的数据 服务实现类
 * </p>
 *
 * @author fq
 * @since 2021-06-01
 */
@Service
public class BusCommentJcllzzfwServiceImpl extends ServiceImpl<BusCommentJcllzzfwMapper, BusCommentJcllzzfw> implements BusCommentJcllzzfwService {

    @Resource
    BusCommentJcllzzfwMapper busCommentJcllzzfwMapper;

    @Override
    public ResponseResult addEventInfo(BusCommentJcllzzfw comment) {
        ResponseResult result = new ResponseResult();
        try{

            List<Map<String,String>> mapList = busCommentJcllzzfwMapper.getOrgIdDeptId(comment.getStreet(),comment.getCommunity());
            if (mapList!=null && mapList.size()>0){
                Map<String,String> dpMap = mapList.get(0);
                comment.setOrgId(dpMap.get("orgId"));
                comment.setOrg(dpMap.get("org"));
                comment.setDeptId(dpMap.get("deptId"));
                comment.setDept(dpMap.get("dept"));
            }

            save(comment);
            result.setCode(200);
            result.setMsg("SUCCESS");
            result.setData("推送成功");
        }
        catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
            result.setMsg("ERROR");
            result.setData("请求失败");
        }
        return result;
    }

    @Override
    public ResponseResult resultFeedback(BusCommentJcllzzfw comment) {
        ResponseResult result = new ResponseResult();
        try{
            updateById(comment);

            //在回馈到监察联络站
            BusCommentJcllzzfw commentJcllzzfw = getById(comment.getId());
            Map<String,String> params = new HashMap<>();
            params.put("reportId", commentJcllzzfw.getReportId());
            params.put("replyContent", commentJcllzzfw.getReplierText());
            JSONObject jsonObject = HttpRequestUtil.getHttpResponseJson("http://10.71.192.112:80/JDD_ZHGJ_API/basis/leavemessage/addWisdomSupervision", params);
            if ("200".equals(jsonObject.get("status"))){
                result.setCode(200);
                result.setMsg("SUCCESS");
                result.setData("反馈完成");
            }else {
                result.setCode(500);
                result.setMsg("ERROR");
                result.setData("请求失败(监察联络站原数据丢失)");
            }
//            result.setCode(200);
//            result.setMsg("SUCCESS");
//            result.setData("反馈完成");
        }
        catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
            result.setMsg("ERROR");
            result.setData("请求失败");
        }
        return result;
    }

}
